<template>
	<div>
		<headerNave :nva-datas="navDatas" v-on:backNav="backNav"></headerNave>
		<components :is="currentView" v-on:changeView="changeView" v-on:backPrev="backPrev" :template-obj="templateObj"></components>
	</div>
</template>
<script>
	import $ from 'jquery'
	import headerNave from '../../../../components/headerNave'
	import { GloabFun, Animation, HttpServer } from '../../../../assets/js/common.js'
	//
	const List = resolve => require(['./List.vue'], resolve)
	const Detail = resolve => require(['./Detail.vue'], resolve)
	const DetectResult = resolve => require(['./DetectResult.vue'], resolve)
	//文件推送
	const FilePushed = resolve => require(['./FilePushed.vue'], resolve)
	//计划任务
	const ScheduleTask = resolve => require(['./ScheduleTask/List.vue'], resolve)
	const AddScheduleTask = resolve => require(['./ScheduleTask/Add.vue'], resolve)
	const EditScheduleTask = resolve => require(['./ScheduleTask/Edit.vue'], resolve)
	export default {
		components: {
			List,
			Detail,
			DetectResult,
			FilePushed,
			ScheduleTask,
			AddScheduleTask,
			EditScheduleTask,
			headerNave
		},
		data() {
			return {
				currentView: "List",
				templateObj: {
					DistrictId: this.subArgs.DistrictId,
					CurrentView: this.subArgs.CurrentView
				},
				navDatas: [{
					name: '设备管理',
					view: ""
				}, {
					name: this.subArgs.CurrentView,
					view: "List"
				}]
			};
		},
		props: {
			subArgs: {
				type: Object,
				default: {}
			}
		},
		methods: {
			changeView(view, obj) {
				GloabFun.clearRecordPreview.call(this);
				obj.DistrictId = this.subArgs.DistrictId;
				obj.CurrentView = this.subArgs.CurrentView;
				Animation.animation($("#mainContent"), function() {
					if(obj) {
						this.navDatas = [{
							name: '设备管理',
							view: ""
						}, {
							name: this.subArgs.CurrentView,
							view: "List"
						}];
						this.templateObj = obj;
						if(view === "Detail") {
							this.navDatas.push({
								name: "自检记录详情->" + obj.devicename,
								view: "Detail"
							});
						}else if(view === "DetectResult") {
							this.navDatas.push({
								name: "设备自检结果",
								view: "DetectResult"
							});
						}else if(view === "FilePushed") {
							this.navDatas.push({
								name: "配置文件推送",
								view: "FilePushed"
							});
						}else if(view === "ScheduleTask") {
							this.navDatas.push({
								name: "计划任务",
								view: "ScheduleTask"
							});
						}else if(view === "AddScheduleTask") {
							this.navDatas.push({
								name: "计划任务",
								view: "ScheduleTask"
							});
							this.navDatas.push({
								name: "创建",
								view: "AddScheduleTask"
							});
						}else if(view === "EditScheduleTask") {
							this.navDatas.push({
								name: "计划任务",
								view: "ScheduleTask"
							});
							this.navDatas.push({
								name: "编辑->" + obj.name,
								view: "EditScheduleTask"
							});
						}
					}
					this.currentView = view;
				}.bind(this));
			},
			backPrev() {
				this.$emit('backPrev');
			},
			backNav(item) {
				if(item.view === "List") {
					this.changeView("List", this.templateObj);
				} else if(item.view === "ScheduleTask") {
					this.changeView("ScheduleTask", this.templateObj);
				}
			}
		}
	}
</script>